home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / PRINTER.H < prev    next >
Text File  |  1992-06-10  |  5KB  |  178 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* printer.h */
  4.  
  5. #ifndef __PRINTER_H
  6. #define __PRINTER_H
  7.  
  8. // OWL headers
  9. #include <owl.h>
  10. #include <objstrm.h>
  11. #include <owldefs.h>
  12. #include <tcollect.h>
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. // Windows header
  19. #include <drivinit.h>
  20.  
  21. // Standard header
  22. #include <string.h>
  23.  
  24. #ifdef __cplusplus
  25. }
  26. #endif
  27.  
  28.  
  29. #define PS_OK 0
  30. #define PS_INVALIDDEVICE -1  // Device parameters (to set device) invalid
  31. #define PS_UNASSOCIATED -2   // Object not associated with a printer
  32.  
  33. // TPrintout banding flags
  34.  
  35. #define PF_GRAPHICS 0x01     // Current band only accepts graphics
  36. #define PF_TEXT 0x02         // Current band only accepts text
  37. #define PF_BOTH 0x03         // Current band accepts both text and graphics
  38.  
  39. /*
  40. TPrintout represents the physical printed document which is to
  41. sent to a printer to be printed. TPrintout does the rendering of
  42. the document onto the printer. For every document, or document
  43. type, a corresponding TPrintout class should be created.
  44. */
  45.  
  46. _CLASSDEF(TPrintout)
  47. class TPrintout: public TStreamable
  48. {
  49. protected:
  50.   Pchar Title;
  51.   BOOL Banding;
  52.   BOOL ForceAllBands;
  53. public:
  54.   TPrintout(Pchar ATitle);
  55.   virtual ~TPrintout();
  56.   virtual void PrintPage(HDC DC, WORD Page, POINT Size, LPRECT Rect, WORD Flags) = 0;
  57.   virtual BOOL IsNextPage();
  58.  
  59.   // The following are pure virtual functions in TStreamable
  60.   // and so must be redefined here to make this an instance class.
  61.   // These should be redefined if you actually want your TPrintout
  62.   // class to be streamable.
  63. private:
  64.   virtual const Pchar streamableName() const
  65.   {
  66.     return "TPrintout";
  67.   }
  68. protected:
  69.   virtual Pvoid read(Ripstream)
  70.   {
  71.     return this;
  72.   }
  73.   virtual void write(Ropstream)
  74.   {}
  75.  
  76.   friend class _CLASSTYPE TPrinter;
  77. };
  78.  
  79. /*
  80. TPrinter represent the physical printer device.  To print a
  81. TPrintout, send the TPrintout to the TPrinter's Print function.
  82. */
  83.  
  84. // DeviceMode functions have no template in windows.h or drivinit.h.
  85. typedef WORD (FAR PASCAL *PTDeviceModeFcn)(HWND, HANDLE, LPSTR, LPSTR);
  86.  
  87. _CLASSDEF(TPrinter)
  88. class TPrinter: public TStreamable
  89. {
  90. protected:
  91.   Pchar Device, Driver, Port;    // Printer device description
  92.   int Status;                    // Device status, error is != PS_OK
  93.   int Error;                     // < 0 if error occurred during print
  94.     HINSTANCE DeviceModule;        // Handle to printer driver module
  95.   PTDeviceModeFcn DeviceMode;    // Function pointer to DevMode
  96.   LPFNDEVMODE ExtDeviceMode;     // Function pointer to ExtDevMode
  97.   PDEVMODE DevSettings;          // Local copy of printer settings
  98.   int DevSettingSize;            // Size of the printer settings
  99.   void GetDefaultPrinter();
  100.  
  101. public:
  102.   TPrinter();
  103.   virtual ~TPrinter();
  104.   void ClearDevice();
  105.   void Configure(PTWindowsObject Window);
  106.   virtual HDC GetDC();
  107.   virtual void ReportError(PTPrintout Printout);
  108.   void SetDevice(Pchar ADevice, Pchar ADriver, Pchar APort);
  109.   void Setup(PTWindowsObject Parent);
  110.   BOOL Print(PTWindowsObject ParentWin, PTPrintout Printout);
  111. private:
  112.   // Private member used by Print
  113.   void CalcBandingFlags();
  114.  
  115.   // The following are pure virtual functions in TStreamable
  116.   // and so must be redefined here to make this an instance class.
  117. private:
  118.   virtual const Pchar streamableName() const
  119.   {
  120.     return "TPrinter";
  121.   }
  122. protected:
  123.   virtual Pvoid read(Ripstream)
  124.   {
  125.     return this;
  126.   }
  127.   virtual void write(Ropstream)
  128.   {}
  129.  
  130.   friend class _CLASSTYPE TPrinterSetupDlg;
  131. };
  132.  
  133. /*
  134. TPrinterSetupDlg is a dialog to modify which printer a TPrinter
  135. object is attached to. It displays all the active printers
  136. in the system allowing the user to select the desired printer.
  137. The dialog also allows the user to call up the printer's
  138. "setup" dialog for further configuration of the printer.
  139. */
  140.  
  141. #define ID_COMBO 100
  142. #define ID_SETUP 101
  143.  
  144. _CLASSDEF(TPrinterSetupDlg)
  145. class TPrinterSetupDlg: public TDialog
  146. {
  147. protected:
  148.   PTPrinter Printer;
  149. public:
  150.   TPrinterSetupDlg(PTWindowsObject AParent, LPSTR TemplateName, PTPrinter APrinter);
  151.   virtual ~TPrinterSetupDlg();
  152.   virtual void TransferData(WORD TransferFlag);
  153.   virtual void IDSetup(RTMessage)
  154.     = [ID_FIRST + ID_SETUP];
  155.   virtual void Cancel(RTMessage)
  156.     = [ID_FIRST + IDCANCEL];
  157. private:
  158.   Pchar OldDevice, OldDriver, OldPort;
  159.   PTNSCollection DeviceCollection;
  160. };
  161.  
  162. #define ID_TITLE 101
  163. #define ID_DEVICE 102
  164. #define ID_PORT 103
  165.  
  166. _CLASSDEF(TPrinterAbortDlg)
  167. class TPrinterAbortDlg: public TDialog
  168. {
  169. public:
  170.   TPrinterAbortDlg(PTWindowsObject AParent, Pchar Template,
  171.     Pchar Title, Pchar Device, Pchar Port);
  172.   virtual void SetupWindow();
  173.   virtual void WMCommand(RTMessage)
  174.     = [WM_FIRST + WM_COMMAND];
  175. };
  176.  
  177. #endif
  178.